<?php

namespace App\Api\Controllers;

use App\Api\Dao\UserMonthMoneyDao;
use App\Api\Logic\CommonLogic;
use App\Helpers\Lib\AliSmsServices;
use App\Models\TongDistrict;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class CommonController extends BaseController
{
    /**
     * 上传文件
     * @return \Illuminate\Http\JsonResponse
     */
    public function uploadImg(CommonLogic $commonLogic,Request $request){
        $data = $request->all();
        $commonLogic->uploadImg($data);
        $path = Storage::putFile('public/images', $request->file('img'));

        return $this->success($path);
    }

    /**
     * 获取项目的品牌介绍
     * @return \Illuminate\Http\JsonResponse
     */
    public function getPinpai(){
        $data = config("base.pinpaijieshao");
        return $this->success($data);
    }

    /**
     * 发送短信验证码
     * @return \Illuminate\Http\JsonResponse
     */
    public function sendSms(CommonLogic $commonLogic,Request $request){
        $data = $request->all();
        $commonLogic->sendSms($data);
        $code = rand(1000,9999);
        AliSmsServices::sendSms($data['phone'],$code);
        return $this->success();
    }

    /**
     * 获取手续费
     * @return \Illuminate\Http\JsonResponse
     */
    public function getCommission(){
        $data = config("withdrawal.shouxufei");
        return $this->success($data);
    }

    /**
     * 小程序审核
     * @return void
     */
    public function getMiniConfig(){
        $data = config("mini.mini_audit");
        return $this->success($data);
    }

    /**
     * 富有支付获取下测试的openid
     * @param Request $request
     * @return void
     */
    public function getServeropenid(Request $request){
        $params = $request->all();
        var_dump($params);
    }

    public function getMonthMoney(Request $request,UserMonthMoneyDao $userMonthMoneyDao){
        $params = $request->all();
        $result = $userMonthMoneyDao->getMonthMoney($params);
        return $this->success($result);
    }
}
